﻿#region File Description 
///////////////////////////////////////////////////////////////////////////////
/// \file MouseStateManager.cs
/// \brief This file stores Mouse State Manager Class (MouseStateManager)
/// \note It performs checks by comparing value changes between mouse states
/// \author Steven Duda
/// \date 18/07/2010
/// \remarks Copyright(c) 2010 LM01 Project Group (Animus Games - ViralFlux)
/// \remarks Some Rights Reserved.
/// Licenced under: Microsoft Reciprocal License (Ms-RL)
/// For More Information see: www.microsoft.com/opensource/licenses.mspx
///////////////////////////////////////////////////////////////////////////////
#endregion

#region Using Statements 
    using Microsoft.Xna.Framework.Input;
#endregion

namespace GameOfLife
{

    /// <summary>
    /// \class MouseStateManager
    /// \author Steven Duda
    /// \brief Helper class for reading input from the mouse.
    /// This class tracks both the current and previous mouse states.
    /// </summary>
	internal static class MouseStateManager
    {
        #region Fields and Properties

        static private MouseState CurrentMouseState = new MouseState();
        static private MouseState LastMouseState; // Mouse State at Last Update

        static internal int x
        {
            get { return CurrentMouseState.X; }
        }
        static internal int y
        {
            get { return CurrentMouseState.Y; }
        }

        #endregion

        #region Public Methods

        /// \brief Stores the last state, then gets the current mouse state
        /// \note Update can be disabled by setting enabled to false
        /// \note This Update is used when the implementing class does not
        /// contain (or need to use) Timed Mouse Events.
        /// \author Steven Duda
        static internal void Update()
        {
            LastMouseState = CurrentMouseState;
            CurrentMouseState = Mouse.GetState();
        }

        // << Button Down Event Methods >>

        /// \brief Checks if the LEFT mouse button was released then pressed
        /// \author Steven Duda
        /// \return LEFT Mouse Button Pressed? (true/false) 
        static internal bool LeftButtonPress()
        {
            return (CurrentMouseState.LeftButton == ButtonState.Pressed &&
                    LastMouseState.LeftButton == ButtonState.Released);
        }

        // << Button Up Event Methods >>

        /// \brief Checks if the LEFT mouse button was pressed then released
        /// \author Steven Duda
        /// \return LEFT Mouse Button Released? (true/false) 
        static internal bool LeftButtonRelease()
        {
            return (CurrentMouseState.LeftButton == ButtonState.Released &&
                    LastMouseState.LeftButton == ButtonState.Pressed);
        }

        /// \brief Checks if the RIGHT mouse button was pressed then released
        /// \author Steven Duda
        /// \return RIGHT Mouse Button Released? (true/false) 
        static internal bool RightButtonRelease()
        {
            return (CurrentMouseState.RightButton == ButtonState.Released &&
                    LastMouseState.RightButton == ButtonState.Pressed);
        }

        /// \brief Checks if the MIDDLE mouse button was pressed then released
        /// \author Steven Duda
        /// \return MIDDLE Mouse Button Released? (true/false) 
        static internal bool MiddleButtonRelease()
        {
            return (CurrentMouseState.MiddleButton == ButtonState.Released &&
               LastMouseState.MiddleButton == ButtonState.Pressed);
        }

        // << Button Held Event Methods >>

        /// \brief Checks if the LEFT mouse button has been held down
        /// \author Steven Duda
        /// \return LEFT Mouse Button Held down? (true/false) 
        static internal bool LeftButtonHeld()
        {
            return (CurrentMouseState.LeftButton == ButtonState.Pressed &&
                    LastMouseState.LeftButton == ButtonState.Pressed);
        }

        /// \brief Checks if the RIGHT mouse button has been held down
        /// \author Steven Duda
        /// \return RIGHT Mouse Button Held down? (true/false) 
        static internal bool RightButtonHeld()
        {
            return (CurrentMouseState.RightButton == ButtonState.Pressed &&
                    LastMouseState.RightButton == ButtonState.Pressed);
        }

        #endregion

    }
}

